package com.azapp.consoleserver.service.web.impl;


import com.azapp.consoleserver.dao.web.AdminDao;
import com.azapp.consoleserver.model.dto.MenuVo;
import com.azapp.consoleserver.model.entity.Admin;
import com.azapp.consoleserver.model.entity.Menu;
import com.azapp.consoleserver.service.web.AdminService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {

    @Resource
    private AdminDao adminDao;


    @Override
    public Admin getAdminByPhone(String phone) {
        return adminDao.getAdminByPhone(phone);
    }

    @Override
    public List<MenuVo> getMenusByAtype(int atype) throws Exception{

        //首先获取这个权限对应的一级目录
        List<MenuVo> menuVoList=adminDao.getFirstLevelMenus(atype);

        //循环，通过这个权限，以及当前一级目录的id，获取对应的二级目录
        for (MenuVo vo:menuVoList){
            List<Menu> menus=adminDao.getSecondLevelMenus(atype,vo.getMenuid());
            //并将二级目录的集合，存入以及目录对象的children属性中
            vo.setChildren(menus);
        }
        return menuVoList;
    }
}
